package com.taotao.web;

import com.taotao.common.EUTreeNode;
import com.taotao.common.TaotaoResult;
import com.taotao.pojo.TbContentCategory;
import com.taotao.service.TbContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/content/category")
public class TbContentCategoryController {

    @Autowired
    private TbContentCategoryService tbContentCategoryService;

    /**
     * 根据parentId查询类别
     * @param parentId
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public List<EUTreeNode> TbContentCategory(@RequestParam(value = "id",defaultValue = "0") long parentId){
        List<EUTreeNode> euTreeNodeList = tbContentCategoryService.TbContentCategory(parentId);
        return euTreeNodeList;
    }

    /**
     * 新增一个类别
     * @param tbContentCategory
     * @return
     */
    @RequestMapping("/create")
    @ResponseBody
    public TaotaoResult createTbContentCategory(TbContentCategory tbContentCategory){
        TaotaoResult taotaoResult = tbContentCategoryService.createTbContentCategory(tbContentCategory);
        return taotaoResult;
    }

    /**
     * 更改类别
     * @param tbContentCategory
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public TaotaoResult updateTbContentCategory(TbContentCategory tbContentCategory){
        TaotaoResult taotaoResult = tbContentCategoryService.updateTbContentCategoryName(tbContentCategory);
        return taotaoResult;
    }

    /**
     * 删除类别
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public TaotaoResult deleteTbContentCategory(Long id){
        TaotaoResult taotaoResult = tbContentCategoryService.deleteTbContentCategory(id);
        return taotaoResult;
    }
}
